package com.hzhjhh.dto;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.apache.commons.collections4.CollectionUtils;

import com.hzhjhh.entity.Sale;

import cn.hutool.core.bean.BeanUtil;

/**
 * 销售表
 * 
 * @TableName sm_sale
 */
public class Sale2DTOUtils {
	
	public static SaleDTO toDTO(Sale sale) {
		if (Objects.isNull(sale)) {
			return null;
		}
		SaleDTO saleDTO = BeanUtil.copyProperties(sale, SaleDTO.class);
		saleDTO.setAmtSubtotal(sale.getSalePrice().multiply(new BigDecimal(sale.getSaleNumber())));
		
		return saleDTO;
	}
	
	public static List<SaleDTO> toDTO(List<Sale> saleList) {
		
		if (CollectionUtils.isEmpty(saleList)) {
			return Collections.emptyList();
		}
		
		return saleList.stream()
				.map(Sale2DTOUtils::toDTO)
				.collect(Collectors.toList());
	}
}